// import com.alibaba.druid.sql.ast.*;
// import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
// import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.List;

#include "SQLAlterTableAlterIndex.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../SQLIndexDefinition.h"
#include "../../dialect/mysql/ast/statement/MySqlTableIndex.h"
#include "../../dialect/mysql/ast/MySqlKey.h"

SQLAlterTableAlterIndex::SQLAlterTableAlterIndex()
{
  indexDefinition->setParent(SharedObject(SQLAlterTableAlterIndex));
}

SQLIndexDefinition_ptr SQLAlterTableAlterIndex::getIndexDefinition()
{
  return indexDefinition;
}

// @Override
void SQLAlterTableAlterIndex::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLAlterTableAlterIndex)))
  {
    if (indexDefinition->getName() != nullptr)
    {
      indexDefinition->getName()->accept(visitor);
    }

    auto it_getColumns = getColumns()->begin();
    for (int i = 0; i < getColumns()->size(); i++)
    {
      std::advance(it_getColumns,i);
      SQLSelectOrderByItem_ptr item = *it_getColumns;
      if (item != nullptr)
      {
        item->accept(visitor);
      }
    }
    auto it_getCovering = getCovering()->begin();
    for (int i = 0; i < getCovering()->size(); i++)
    {
      std::advance(it_getCovering,i);
      SQLName_ptr item = *it_getCovering;
      if (item != nullptr)
      {
        item->accept(visitor);
      }
    }
  }
  visitor->endVisit(SharedObject(SQLAlterTableAlterIndex));
}

BOOL_ptr SQLAlterTableAlterIndex::isUnique()
{
  return (indexDefinition->getType() != nullptr && indexDefinition->getType()->c_str() == "UNIQUE")?BOOL::TRUE:BOOL::FALSE;
}

void SQLAlterTableAlterIndex::setUnique(BOOL_ptr unique)
{
  indexDefinition->setType(make_string_ptr("UNIQUE"));
}

SQLSelectOrderByItem_list_ptr SQLAlterTableAlterIndex::getItems()
{
  return indexDefinition->getColumns();
}

void SQLAlterTableAlterIndex::addItem(SQLSelectOrderByItem_ptr item)
{
  if (item != nullptr)
  {
    item->setParent(SharedObject(SQLAlterTableAlterIndex));
  }
  indexDefinition->getColumns()->push_back(item);
}

SQLName_ptr SQLAlterTableAlterIndex::getName()
{
  return indexDefinition->getName();
}

void SQLAlterTableAlterIndex::setName(SQLName_ptr name)
{
  indexDefinition->setName(name);
}

string_ptr SQLAlterTableAlterIndex::getType()
{
  return indexDefinition->getType();
}

void SQLAlterTableAlterIndex::setType(string_ptr type)
{
  indexDefinition->setType(type);
}

string_ptr SQLAlterTableAlterIndex::getUsing()
{
  if (indexDefinition->hasOptions())
  {
    return indexDefinition->getOptions()->getIndexType();
  }
  return nullptr;
}

void SQLAlterTableAlterIndex::setUsing(string_ptr using_)
{
  indexDefinition->getOptions()->setIndexType(using_);
}

BOOL_ptr SQLAlterTableAlterIndex::isKey()
{
  return indexDefinition->isKey();
}

void SQLAlterTableAlterIndex::setKey(BOOL_ptr key)
{
  indexDefinition->setKey(key);
}

void SQLAlterTableAlterIndex::cloneTo(MySqlTableIndex_ptr x)
{
  indexDefinition->cloneTo(x->getIndexDefinition());
}

void SQLAlterTableAlterIndex::cloneTo(MySqlKey_ptr x)
{
  indexDefinition->cloneTo(x->getIndexDefinition());
}

SQLExpr_ptr SQLAlterTableAlterIndex::getComment()
{
  if (indexDefinition->hasOptions())
  {
    return indexDefinition->getOptions()->getComment();
  }
  return nullptr;
}

void SQLAlterTableAlterIndex::setComment(SQLExpr_ptr comment)
{
  if (comment != nullptr)
  {
    comment->setParent(SharedObject(SQLAlterTableAlterIndex));
  }
  indexDefinition->getOptions()->setComment(comment);
}

SQLExpr_ptr SQLAlterTableAlterIndex::getKeyBlockSize()
{
  if (indexDefinition->hasOptions())
  {
    return indexDefinition->getOptions()->getKeyBlockSize();
  }
  return nullptr;
}

void SQLAlterTableAlterIndex::setKeyBlockSize(SQLExpr_ptr keyBlockSize)
{
  indexDefinition->getOptions()->setKeyBlockSize(keyBlockSize);
}

string_ptr SQLAlterTableAlterIndex::getParserName()
{
  if (indexDefinition->hasOptions())
  {
    return indexDefinition->getOptions()->getParserName();
  }
  return nullptr;
}

void SQLAlterTableAlterIndex::setParserName(string_ptr parserName)
{
  indexDefinition->getOptions()->setParserName(parserName);
}

BOOL_ptr SQLAlterTableAlterIndex::isHashMapType()
{
  return indexDefinition->isHashMapType();
}

void SQLAlterTableAlterIndex::setHashMapType(BOOL_ptr hashMapType)
{
  indexDefinition->setHashMapType(hashMapType);
}

SQLExpr_ptr SQLAlterTableAlterIndex::getOption(long hash64)
{
  return indexDefinition->getOption(hash64);
}

string_ptr SQLAlterTableAlterIndex::getDistanceMeasure()
{
  return indexDefinition->getDistanceMeasure();
}

string_ptr SQLAlterTableAlterIndex::getAlgorithm()
{
  return indexDefinition->getAlgorithm();
}

void SQLAlterTableAlterIndex::addOption(string_ptr name, SQLExpr_ptr value)
{
  indexDefinition->addOption(name, value);
}

SQLAssignItem_list_ptr SQLAlterTableAlterIndex::getOptions()
{
  return indexDefinition->getCompatibleOptions();
}

BOOL_ptr SQLAlterTableAlterIndex::isGlobal()
{
  return indexDefinition->isGlobal();
}

void SQLAlterTableAlterIndex::setGlobal(BOOL_ptr global)
{
  indexDefinition->setGlobal(global);
}

SQLExpr_ptr SQLAlterTableAlterIndex::getDbPartitionBy()
{
  return indexDefinition->getDbPartitionBy();
}

void SQLAlterTableAlterIndex::setDbPartitionBy(SQLExpr_ptr x)
{
  indexDefinition->setDbPartitionBy(x);
}

SQLExpr_ptr SQLAlterTableAlterIndex::getTablePartitionBy()
{
  return indexDefinition->getTbPartitionBy();
}

void SQLAlterTableAlterIndex::setTablePartitionBy(SQLExpr_ptr x)
{
  indexDefinition->setTbPartitionBy(x);
}

SQLExpr_ptr SQLAlterTableAlterIndex::getTablePartitions()
{
  return indexDefinition->getTbPartitions();
}

void SQLAlterTableAlterIndex::setTablePartitions(SQLExpr_ptr x)
{
  indexDefinition->setTbPartitions(x);
}

// @Override
SQLName_list_ptr SQLAlterTableAlterIndex::getCovering()
{
  return indexDefinition->getCovering();
}

// @Override
SQLSelectOrderByItem_list_ptr SQLAlterTableAlterIndex::getColumns()
{
  return indexDefinition->getColumns();
}
